package org.school.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.school.entity.Cai;
import org.school.dao.CaiDao;
import org.school.entity.message2;
import org.school.service.CaiService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Cai)表服务实现类
 *
 * @author skyme
 * @since 2023-01-13 17:44:31
 */
@Service("caiService")
public class CaiServiceImpl implements CaiService {
    @Resource
    private CaiDao caiDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Cai queryById(Integer id) {
        return this.caiDao.queryById(id);
    }

    @Override
    public PageInfo<Cai> queryByPage(int pageNum, int size) {
        PageHelper.startPage(pageNum, size);
        List<Cai> lists = this.caiDao.queryCaiInfo();
        PageInfo<Cai> pageInfo = new PageInfo<>(lists);
        return pageInfo;
    }




    /**
     * 新增数据
     *
     * @param cai 实例对象
     * @return 实例对象
     */
    @Override
    public Cai insert(Cai cai) {
        this.caiDao.insert(cai);
        return cai;
    }

    /**
     * 修改数据
     *
     * @param cai 实例对象
     * @return 实例对象
     */
    @Override
    public Cai update(Cai cai) {
        this.caiDao.update(cai);
        return this.queryById(cai.getId());
    }

    @Override
    public boolean deleteById(Integer id) {
        return false;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public message2 deleteByName(String shopname, String cname) {
        message2 mes=new message2("删除失败",0);
       if(this.caiDao.deleteByName(shopname,cname) > 0) {
           mes.setContent("删除成功");
           mes.setStatus(1);
       }
        return mes;
    }

    @Override
    public message2 uploadImg(MultipartFile file) {

        return null;
    }
}
